﻿var gameObjectFactory = (function () {
    var getFigure = function (id, rotation) {
        rotation = rotation || 0;

        switch (id) {
            case "dash":
                currentFigure = gameObjects.Dash.init(rotation);
                break;
            case "tElement":
                currentFigure = gameObjects.TElement.init(rotation);
                break;
            case "lElement":
                currentFigure = gameObjects.LElement.init(rotation);
                break;
            case "jElement":
                currentFigure = gameObjects.JElement.init(rotation);
                break;
            case "zElement":
                currentFigure = gameObjects.ZElement.init(rotation);
                break;
            case "sElement":
                currentFigure = gameObjects.SElement.init(rotation);
                break;
            case "square":
                currentFigure = gameObjects.Square.init(rotation);
                break;
            default:
                throw new Error("The selected figure is invalid.");
                break;
        }

        currentFigure._addHandlers();
        return currentFigure;
    };

    var getRandomFigure = function () {
        var index = Math.floor(Math.random() * Figures.length);
        var figureId = Figures[index];
        getFigure(figureId);
    };

    return {
        getFigure: getFigure,
        getRandomFigure: getRandomFigure
    };
})();